﻿function getXmlHttp1111() {
    var xmlHttp;
    try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
            xmlHttp = false;
        }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

function CommentGuest(CommentId){
    var adminComment = document.getElementById("comment-" + CommentId);

    alert(JSON.stringify({
        CommentId: parseInt(CommentId),
        AdminCommentValue: adminComment.value
    }));

    $.ajax({
        url: "Guest/SetAdminComment",
        type: "POST",
        dataType: "text",
        data: JSON.stringify({
            CommentId: parseInt(CommentId),
            AdminCommentValue: adminComment.value
        }),
        contentType: "application/json; charset=utf-8",
        beforeSend: function () {
            adminComment.style.backgroundColor = "#FFA";
        },
        error: function (data, m1, m2) {
            adminComment.style.backgroundColor = "#FAA";
            alert("data: " + data + ";\nm1: " + m1 + ";\nm2: " + m2);
        },
        success: function (data) {
            if (data == "Ok") {
                adminComment.style.backgroundColor = "#AFA";
            } else {
                adminComment.style.backgroundColor = "#FAA";
                // Unexpected error
                alert("Произошла непредвиденная ошибка. Пожалуйста, обратитесь к разработчику");
            }
        }
    })
}